# -*- coding: utf-8 -*-
"""
时间工具模块
"""

import datetime
import time

def format_duration(seconds):
    """格式化持续时间"""
    if not seconds:
        return "0秒"
    
    hours = seconds // 3600
    minutes = (seconds % 3600) // 60
    secs = seconds % 60
    
    if hours > 0:
        return f"{hours}小时{minutes}分{secs}秒"
    elif minutes > 0:
        return f"{minutes}分{secs}秒"
    else:
        return f"{secs}秒"

def get_today_date():
    """获取今天日期字符串"""
    return datetime.datetime.now().strftime('%Y-%m-%d')

def get_current_time():
    """获取当前时间字符串"""
    return datetime.datetime.now().strftime('%H:%M:%S')

def calculate_time_difference(start_time, end_time=None):
    """计算时间差（秒）"""
    if end_time is None:
        end_time = datetime.datetime.now()
    return int((end_time - start_time).total_seconds())

def is_same_day(date1, date2=None):
    """判断两个日期是否是同一天"""
    if date2 is None:
        date2 = datetime.datetime.now().date()
    
    if isinstance(date1, str):
        date1 = datetime.datetime.strptime(date1, '%Y-%m-%d').date()
    elif isinstance(date1, datetime.datetime):
        date1 = date1.date()
    
    if isinstance(date2, datetime.datetime):
        date2 = date2.date()
    
    return date1 == date2